package com.example.hospital.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.hospital.pojo.Rb;
import com.example.hospital.pojo.RespBean;
import com.example.hospital.pojo.Ro;
import com.example.hospital.pojo.RoVO;
import com.example.hospital.service.IRoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@Api(tags = "RoController")
@RestController
@RequestMapping("/Ro")
public class RoController {
    @Autowired
    private IRoService iRoService;
    @ApiOperation(value = "为病人添加业务属性标签")
    @PostMapping("/")
    public RespBean addBasic(@RequestBody Ro ro){
        LocalDate endDate = ro.getEndDate();
        ro.setEndDate(endDate);
        ro.setCreateDate(LocalDate.now());
        if(iRoService.save(ro)){
            return RespBean.success("添加成功");
        }
        return RespBean.error("添加失败");
    }
    @ApiOperation(value = "删除病人业务信息标签")
    @DeleteMapping("/delete")
    public RespBean deleteByid(@RequestBody RoVO roVO){
        int id = roVO.getId();
        int oid = roVO.getOid();
        LambdaQueryWrapper<Ro> lam = new LambdaQueryWrapper<>();
        lam.eq(Ro::getPid,id).eq(Ro::getOid,oid);
        if(iRoService.remove(lam)){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }

}
